﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace temperatur
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {

		        int startTemp = int.Parse(starttemp.Text.ToString());
                int slutTemp = int.Parse(sluttemp.Text.ToString());
                int tempSteg = int.Parse(tempsteg.Text.ToString());

                bool cToF = CtoF.Checked;
          
			        TemperatureConverter TC = new TemperatureConverter();

                        if (cToF)
                        {
                            TableRow title = new TableRow();
                            TableCell Celcius = new TableCell();
                            TableCell Fahrenheit = new TableCell();
                            Celcius.Controls.Add(new LiteralControl("C°"));
                            Fahrenheit.Controls.Add(new LiteralControl("F°"));
                            title.Cells.Add(Celcius);
                            title.Cells.Add(Fahrenheit);
                            TempTable.Rows.Add(title);

                            for (int i = startTemp; i <= slutTemp; i += tempSteg)
                            {
                                TableRow r = new TableRow();
                                TableCell c = new TableCell();
                                c.Controls.Add(new LiteralControl(i.ToString()));
                                r.Cells.Add(c);
                                int converted = TC.CelsiusToFahrenheit(i);
                                TableCell c2 = new TableCell();
                                c2.Controls.Add(new LiteralControl(converted.ToString()));
                                r.Cells.Add(c2);
                                TempTable.Rows.Add(r);
                                TempTable.Visible = true;

                            }
                        }
                        else
                        {
                            TableRow title = new TableRow();
                            TableCell Celcius = new TableCell();
                            TableCell Fahrenheit = new TableCell();
                            Celcius.Controls.Add(new LiteralControl("C°"));
                            Fahrenheit.Controls.Add(new LiteralControl("F°"));
                            title.Cells.Add(Fahrenheit);
                            title.Cells.Add(Celcius);
                            TempTable.Rows.Add(title);

                            for (int i = startTemp; i < slutTemp; i += tempSteg)
                            {
                                TableRow r = new TableRow();
                                TableCell c = new TableCell();
                                c.Controls.Add(new LiteralControl(i.ToString()));
                                r.Cells.Add(c);
                                int converted = TC.FahrenheitToCelsius(i);
                                TableCell c2 = new TableCell();
                                c2.Controls.Add(new LiteralControl(converted.ToString()));
                                r.Cells.Add(c2);
                                TempTable.Rows.Add(r);
                                TempTable.Visible = true;
                            }
                        }
                    }
        }
    }
}